package com.kukudexin.time.mayikt.entity;

import java.util.Objects;

/**
 * @author: 酷酷的鑫
 * @Date: 2022/1/11 13:36
 * @description:
 */
public class UserEntity {
    private String userName;
    private int age;

    public UserEntity() {

    }

    public UserEntity(String userName, int age) {
        this.userName = userName;
        this.age = age;
    }

    public String getUserName() {
        return userName;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "UserEntity{" +
                "userName='" + userName + '\'' +
                ", age=" + age +
                '}';
    }

    //    @Override
//    public int hashCode() {
//        return userName.hashCode();
//    }
//
//
//    public boolean equals(Object obj) {
//        if (obj instanceof UserEntity)
//            return userName.equals(((UserEntity) obj).userName) && age == (((UserEntity) obj).age);
//        else
//            return false;
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserEntity that = (UserEntity) o;
        return getAge() == that.getAge() &&
                Objects.equals(getUserName(), that.getUserName());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getUserName(), getAge());
    }

    public static void main(String[] args) {
        Long id = 897121053035753472L;
        System.out.println(Objects.hash(id));
    }
}
